package com.bolang.onlycode.demo.question;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class Profiler {
    //第一次get()方法调用时会进行初始化（如果set方法没有调用），每个线程会调用一次
    private static final ThreadLocal<Map<String,String>> TIME_THREADLOCAL = new ThreadLocal<>();

    public static final void begin(){
        HashMap<String, String> map = new HashMap<>();
        map.put("1","2");
        map.put("3","4");
        TIME_THREADLOCAL.set(map);

    }
//    public static final long end(){
//        return System.currentTimeMillis() -TIME_THREADLOCAL.get();
//    }
    public static void main(String[] args) throws InterruptedException {
        HashMap<String, String> map = new HashMap<>();
        map.put("5","6");
        map.put("7","8");

        Profiler.begin();
        TIME_THREADLOCAL.set(map);
        TIME_THREADLOCAL.set(map);
        Thread.sleep(1000);
        new Thread(()->{
            TIME_THREADLOCAL.set(map);
            map.put("5","10");
            map.put("7","11");
            TIME_THREADLOCAL.set(map);
            System.out.println(Thread.currentThread().getName()+TIME_THREADLOCAL.get());
        },"AA").start();
        ThreadLocal<Map<String,String>> threadLocal=new ThreadLocal<>();
        ThreadLocal<Map<String,String>> threadLocal1=new ThreadLocal<>();
        System.out.println(Thread.currentThread().getName()+TIME_THREADLOCAL.get());
        int i=1;




    }
}
